package chapter06

/**
  * create by undeRdoG on  2021-06-02  10:49
  * 凡心所向，素履以往，生如逆旅，一苇以航。
  */
object Test07_Inherit {


  /**
    * 子类的主构造器调用之前，一定要调用父类的主构造器
    **/

  def main(args: Array[String]): Unit = {
    val Student1 = new Student7("alice", 18)

    val student2 = new Student7("bob", 20, "11")
  }

}


// 定义一个父类
class Person7() {

  var name: String = _

  var age: Int = _

  println("1.父类的主构造器被调用")

  def this(name: String, age: Int) {
    this()
    println("2.父类的辅助构造器被调用")
    this.name = name
    this.age = age
  }

  def printInfo(): Unit = {
    println(s"Person: $name  $age")
  }

}

class Student7(name: String, age: Int) extends Person7 {

  var StuNo: String = _
  println("3.子类的主构造器被调用")

  def this(name: String, age: Int, stuNo: String) {

    this(name, age)
    println("4.子类的辅助构造器调用")
    this.StuNo = stuNo
  }

  override def printInfo(): Unit = {
    println(s"Student: $name  $age $StuNo")

  }
}